﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Weblications.Sango.Entities;
using Pixysoft.Framework.Verifications;

namespace Pixysoft.Weblications.Sango.Environment
{
    class SysQueueHelper
    {
        private static List<Sys_Queue> orms = new List<Sys_Queue>();

        public static void initialize()
        {
            orms = SettingHelper.GetNoebe().EntityNoebeCommand.Select<Sys_Queue>();

            LoggerHelper.Info("initialize Sys_Queue.countin {0}", orms.Count);
        }

        public static List<Sys_Queue> searchAll()
        {
            return orms;
        }

        public static List<Sys_Queue> searchDefaultByType(long queueTypecode)
        {
            List<Sys_Queue> list = new List<Sys_Queue>();

            foreach (Sys_Queue orm in orms)
            {
                if (orm.Queuetypecode != queueTypecode)
                    continue;

                if (!SettingHelper.BooleanValue(orm.Isdefault))
                    continue;

                list.Add(orm);
            }

            return list;
        }

        public static List<Sys_Queue> searchByType(long queueTypecode)
        {
            List<Sys_Queue> list = new List<Sys_Queue>();

            foreach (Sys_Queue orm in orms)
            {
                if (orm.Queuetypecode != queueTypecode)
                    continue;

                list.Add(orm);
            }

            return list;
        }

        public static Sys_Queue searchByCode(long queueSerialcode)
        {
            foreach (Sys_Queue orm in orms)
            {
                if (orm.Queueserialcode != queueSerialcode)
                    continue;

                return orm;
            }

            throw Exceptions.VerificationFailedException(queueSerialcode);
        }
    }
}
